﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using BLL;
using MODEL;

internal class LoginIn
{
    public void Get() { }
}
public partial class Login : System.Web.UI.Page
{
    //System.ComponentModel.Component
    protected string strNameErr = "hid";
    protected string strPwdErr = "hid";

    //每次访问都会调用此方法(不管是url还是表单提交)
    protected void Page_Load(object sender, EventArgs e)
    {
                
        if (IsPostBack)//点击按钮调用(服务器控件触发的页面回传)
        {
            if (Request.Form["txtVCode"] == Session["vcode"].ToString())
            {
                string txtUName = Request.Form["txtUName"];
                string txtPwd = Request.Form["txtPwd"];
                StudentModel model = new StudentBLL().QueryByCondition(txtUName, txtPwd);
                if (model != null)
                {
                    string isAlwayLogin = Request.Form["IsAlwayLogin"];
                    Response.Write(isAlwayLogin);
                    if (isAlwayLogin == "1")
                    {
                        HttpCookie cook = new HttpCookie("Sid", model.SID.ToString());
                        cook.Expires = DateTime.Now.AddDays(2);
                        Response.Cookies.Add(cook);
                    }
                    else
                    {
                        Session["Sid"] = model.SID;
                    }
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    Response.Write("Error");
                }
            }
        }
        else//页面
        {
 
        }
        Response.Write("我每次都被调用啦！"+IsPostBack.ToString());
    }
}


//Response.Write(Request.UrlReferrer.ToString());
//        if (!string.IsNullOrEmpty(Request.Form["pback"]))
//        {
//            string uName = Request.Form["txtUName"];
//            string uPwd = Request.Form["txtPwd"];
//            Regex r = new Regex(@"^[0-9a-zA-Z]{6,18}$");
//            if (string.IsNullOrEmpty(uName)||!r.IsMatch(uName))
//            {
//                strNameErr = "errMsg";
//            }
//            else if (string.IsNullOrEmpty(uPwd) || !r.IsMatch(uPwd))
//            {
//                strPwdErr = "errMsg";
//            }
//            else
//            {
//            }
//        }